package com.zhongkun.datahome.web.rest;

import java.util.List;
import javax.annotation.Resource;

import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.service.domain.CustomerFamily;
import com.zhongkun.datahome.service.req.IdsBody;
import com.zhongkun.datahome.service.req.cmd.family.CustomerFamilyCmd;
import com.zhongkun.datahome.service.req.qry.family.CustomerFamilyQry;
import com.zhongkun.datahome.service.res.family.CustomerFamilyVo;
import com.zhongkun.datahome.service.service.ICustomerFamilyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongkun.datahome.common.annotation.Log;
import com.zhongkun.datahome.common.core.controller.BaseController;
import com.zhongkun.datahome.common.enums.BusinessType;

/**
 * 客户家庭Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Api(value = "家庭管理")
@RestController
@RequestMapping("/core/family")
public class CustomerFamilyController extends BaseController {
    @Resource
    private ICustomerFamilyService customerFamilyService;

    @ApiOperation("查询客户家庭成员")
    @PreAuthorize("@ss.hasPermi('core:family:members')")
    @GetMapping("/members")
    public R<List<CustomerFamilyVo>> listMembers(CustomerFamilyQry qry) {
        return R.ok(customerFamilyService.listMembers(qry));
    }

    @ApiOperation("新增客户家庭成员")
    @PreAuthorize("@ss.hasPermi('core:family:addMember')")
    @Log(title = "客户家庭", businessType = BusinessType.INSERT)
    @PostMapping("/addMember")
    public R<Long> addMember(@RequestBody CustomerFamilyCmd cmd) {
        return R.ok(customerFamilyService.addMember(cmd));
    }

    @ApiOperation("修改客户家庭成员")
    @PreAuthorize("@ss.hasPermi('core:family:editMember')")
    @Log(title = "客户家庭", businessType = BusinessType.UPDATE)
    @PutMapping("/editMember")
    public R<Void> editMember(@RequestBody CustomerFamilyCmd cmd) {
        customerFamilyService.editMember(cmd);
        return R.ok();
    }

    @ApiOperation("删除客户家庭成员")
    @PreAuthorize("@ss.hasPermi('core:family:removeMember')")
    @Log(title = "客户家庭", businessType = BusinessType.DELETE)
	@DeleteMapping("/removeMember")
    public R<Void> removeMember(@RequestBody IdsBody idsBody) {
        customerFamilyService.removeMember(idsBody.getIds());
        return R.ok();
    }
}
